package com.example.teachingSystem.controller;

import com.example.teachingSystem.pojo.form.role.AddRoleForm;
import com.example.teachingSystem.pojo.form.role.ChangeRoleInfoForm;
import com.example.teachingSystem.pojo.form.role.RoleMenuForm;
import com.example.teachingSystem.pojo.form.role.RolePageQuery;
import com.example.teachingSystem.pojo.form.user.UserRoleForm;
import com.example.teachingSystem.pojo.vo.OptionVo;
import com.example.teachingSystem.pojo.vo.RoleInfoVo;
import com.example.teachingSystem.service.SysRoleMenuService;
import com.example.teachingSystem.service.SysRoleService;
import com.example.teachingSystem.utils.result.PageResult;
import com.example.teachingSystem.utils.result.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/role")
@Tag(name = "3.角色模块")
public class RoleController {
    @Autowired
    private SysRoleService sysRoleService;

    @Autowired
    private SysRoleMenuService sysRoleMenuService;

    @GetMapping("/one/{id}")
    @Operation(summary = "根据id获取角色", security = {@SecurityRequirement(name = "Authorization")})
    public Result<RoleInfoVo> getRoleById(@PathVariable Long id) {
        return sysRoleService.getRoleById(id);
    }

    @GetMapping("/more")
    @Operation(summary = "获取角色分页", security = {@SecurityRequirement(name = "Authorization")})
    public PageResult<RoleInfoVo> getRoleById(RolePageQuery pageQuery) {
        return sysRoleService.getRolePage(pageQuery);
    }

    @PostMapping("/one")
    @Operation(summary = "添加角色", security = {@SecurityRequirement(name = "Authorization")})
    public Result<String> addRole(@RequestBody AddRoleForm addRoleForm) {
        return sysRoleService.addRole(addRoleForm);
    }

    @PutMapping("/one")
    @Operation(summary = "修改角色", security = {@SecurityRequirement(name = "Authorization")})
    public Result<String> updateRole(@RequestBody ChangeRoleInfoForm  changeRoleInfoForm) {
        return sysRoleService.updateRole(changeRoleInfoForm);
    }

    @PutMapping("/one/status/{id}")
    @Operation(summary = "取消停用角色", security = {@SecurityRequirement(name = "Authorization")})
    public Result<String> unDisableRoleStatus(@PathVariable Long id){
        return sysRoleService.changeRoleStatus(id,false);
    }

    @DeleteMapping("/one/status/{id}")
    @Operation(summary = "停用角色", security = {@SecurityRequirement(name = "Authorization")})
    public Result<String> disableRoleStatus(@PathVariable Long id){
        return sysRoleService.changeRoleStatus(id,true);
    }

    @PutMapping("/one/deleted/{id}")
    @Operation(summary = "恢复角色", security = {@SecurityRequirement(name = "Authorization")})
    public Result<String> recoverRole(@PathVariable Long id){
        return sysRoleService.changeRoleDeleted(id,false);
    }

    @DeleteMapping("/one/deleted/{id}")
    @Operation(summary = "删除角色", security = {@SecurityRequirement(name = "Authorization")})
    public Result<String> deleteRole(@PathVariable Long id){
        return sysRoleService.changeRoleDeleted(id,true);
    }

    @GetMapping("/option")
    @Operation(summary = "获取角色选项", security = {@SecurityRequirement(name = "Authorization")})
    public Result<List<OptionVo>> deleteRole(){
        return sysRoleService.getRoleOptions();
    }

    @PostMapping("/menu")
    @Operation(summary = "为角色添加菜单(管理员)", security = {@SecurityRequirement(name = "Authorization")})
    public Result<String> addRoleMenus(@RequestBody RoleMenuForm roleMenuForm){
        return sysRoleMenuService.addRoleMenus(roleMenuForm);
    }

    @DeleteMapping("/menu")
    @Operation(summary = "为角色删除菜单(管理员)", security = {@SecurityRequirement(name = "Authorization")})
    public Result<String> deleteUserRole(RoleMenuForm roleMenuForm){
        return sysRoleMenuService.deleteRoleMenus(roleMenuForm);
    }
}
